define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_log/index' + location.search,
                    add_url: 'order_log/add',
                    edit_url: 'order_log/edit',
                    del_url: 'order_log/del',
                    multi_url: 'order_log/multi',
                    import_url: 'order_log/import',
                    table: 'order_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'data_source_id', title: __('Data_source_id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'country_ids', title: __('Country_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'material_id', title: __('Material_id')},
                        {field: 'price', title: __('Price')},
                        {field: 'display_num', title: __('Display_num')},
                        {field: 'total_num', title: __('Total_num')},
                        {field: 'active_num', title: __('Active_num')},
                        {field: 'new_num', title: __('New_num')},
                        {field: 'target_num', title: __('Target_num')},
                        {field: 'complete_num', title: __('Complete_num')},
                        {field: 'base_num', title: __('Base_num')},
                        {field: 'eat_num', title: __('Eat_num')},
                        {field: 'click_num', title: __('Click_num')},
                        {field: 'total_click_num', title: __('Total_click_num')},
                        {field: 'conversion_rate', title: __('Conversion_rate'), operate:'BETWEEN'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'whatsup_status', title: __('Whatsup_status'), searchList: {"0":__('Whatsup_status 0'),"1":__('Whatsup_status 1'),"2":__('Whatsup_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'admin_whatsup_status', title: __('Admin_whatsup_status'), searchList: {"0":__('Admin_whatsup_status 0'),"1":__('Admin_whatsup_status 1'),"2":__('Admin_whatsup_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'whatsup_url', title: __('Whatsup_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
